package com.swind.fast.modules.app.railway.report.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.swind.fast.common.api.vo.Result;
import com.swind.fast.common.system.query.QueryGenerator;
import com.swind.fast.common.util.oConvertUtils;
import com.swind.fast.common.util.CommonUtils;
import com.swind.fast.common.util.MinioUtil;

import com.swind.fast.modules.app.railway.report.entity.RailwayReportTaskWorkload;
import com.swind.fast.modules.app.railway.report.service.IRailwayReportTaskWorkloadService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import lombok.extern.slf4j.Slf4j;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;

@RestController
@RequestMapping("/app/railway/report/task")
@Slf4j
// @Api(tags="报表模块")
@ApiSort(value = 1)
public class RailwayReportTaskController {
    private String defaultOrgCode = "A01A02A01";

    @Autowired
    private IRailwayReportTaskWorkloadService railwayProjectService;

    @ApiOperationSupport(order = 100)
    // @ApiOperation("工作量报表")
    @GetMapping(value = "/workload/list")
    public Result<?> workloadList(RailwayReportTaskWorkload railwayProject,
                                      @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                      @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                      HttpServletRequest req) {

        QueryWrapper<RailwayReportTaskWorkload> queryWrapper = QueryGenerator.initQueryWrapper(railwayProject, req.getParameterMap());
        Page<RailwayReportTaskWorkload> page = new Page<RailwayReportTaskWorkload>(pageNo, pageSize);
        IPage<RailwayReportTaskWorkload> pageList = railwayProjectService.page(page, queryWrapper);

        return Result.OK(pageList);
    }

    @ApiOperationSupport(order = 99)
    // @ApiOperation("工作量报表 - ID查看")
    @GetMapping(value = "/workload")
    public Map<String, Object> workloadById(@RequestParam(name="projectId", required=true) String projectId, HttpServletRequest req) {
        Map<String, Object> result = railwayProjectService.getWorkloadPieChart(projectId);
        return result;
    }

    @ApiOperationSupport(order = 99)
    // @ApiOperation("工作量报表 - ID查看图表")
    @GetMapping(value = "/workload/project/chart")
    public Map<String, Object> workloadChartById(@RequestParam(name="projectId", required=true) String projectId, HttpServletRequest req) {
        Map<String, Object> result = railwayProjectService.getWorkloadChart(projectId);
        return result;
    }

    @ApiOperationSupport(order = 99)
    // @ApiOperation("工作量报表 - ID查看详情")
    @GetMapping(value = "/workload/project/detail")
    public Map<String, Object> workloadDetailById(@RequestParam(name="projectId", required=true) String projectId, HttpServletRequest req) {
        Map<String, Object> result = railwayProjectService.getWorkloadDetail(projectId);
        return result;
    }

    @ApiOperationSupport(order = 99)
    // @ApiOperation("工作量报表 - ID查看详情")
    @GetMapping(value = "/big/screen/project")
    public Result<?> getBigScreenProject(@RequestParam(name="orgCode", required=true) String orgCode, HttpServletRequest req) {
        // log.info("getBigScreenProject: {}", orgCode);
        Map<String, Object> result = railwayProjectService.getBigScreenProjectCount(defaultOrgCode);
        return Result.OK(result);
    }

    // @ApiOperationSupport(order = 99)
    // @ApiOperation("人员数量报表 - ID查看详情")
    @GetMapping(value = "/big/screen/person")
    public Result<?> getBigScreenPerson(@RequestParam(name="orgCode", required=true) String orgCode, HttpServletRequest req) {
        // log.info("getBigScreenProject: {}", orgCode);
        Map<String, Object> result = railwayProjectService.getBigScreenPersonCount(defaultOrgCode);
        return Result.OK(result);
    }

    // @ApiOperationSupport(order = 99)
    // @ApiOperation("人员数量报表 - ID查看详情")
    @GetMapping(value = "/big/screen/pproject")
    public Result<?> getBigScreenPproject(@RequestParam(name="orgCode", required=true) String orgCode, HttpServletRequest req) {
        // log.info("getBigScreenProject: {}", orgCode);
        List<Map<String, String>> result = railwayProjectService.getBigScreenProjectPointCount(defaultOrgCode);
        return Result.OK(result);
    }

}
